#include<vector>
using namespace std;
class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        int val = 0;
        for (int i = 0; i < nums.size(); i++)
            val ^= nums[i];
        val = val - ((val - 1) & val);

        int first = 0;
        int second = 0;
        for (int i = 0; i < nums.size(); i++) {
            if ((val & nums[i]) != 0)
                first ^= nums[i];
            else
                second ^= nums[i];
        }
        vector<int>res = { first,second };
        return res;
    }
};